@echo off
chcp 65001 >nul

REM XPath Locator - Complete Startup Script

echo =========================================
echo XPath Locator Tool - Starting Services
echo =========================================
echo.

REM Start backend service
echo [1/2] Starting Backend Service...
start "XPath Backend" cmd /k "cd /d %~dp0 && call start_backend.bat"

REM Wait for backend to initialize
echo Waiting for backend to initialize...
timeout /t 3 /nobreak >nul

REM Start frontend service  
echo [2/2] Starting Frontend Service...
start "XPath Frontend" cmd /k "cd /d %~dp0 && call start_frontend.bat"

echo.
echo =========================================
echo Services are starting in separate windows
echo =========================================
echo.
echo Backend Service:  http://127.0.0.1:8000
echo Frontend Service: http://localhost:5173  
echo API Documentation: http://127.0.0.1:8000/docs
echo Health Check: http://127.0.0.1:8000/health
echo.
echo IMPORTANT:
echo - Wait for both services to fully start (about 10-15 seconds)
echo - Check both command windows for "ready" messages
echo - Then open http://localhost:5173 in your browser
echo.
echo =========================================

REM Wait and auto-open browser
echo Waiting 10 seconds before opening browser...
timeout /t 10 /nobreak >nul

echo Opening browser...
start http://localhost:5173

echo.
echo If the page doesn't load, please:
echo 1. Check both service windows for errors
echo 2. Wait a bit longer for services to start
echo 3. Manually open http://localhost:5173
echo.

pause